﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reports.Core;
using Pixysoft.Framework.Reports.Controller;
using System.Data;
using Pixysoft.Framework.Configurations;

namespace Pixysoft.Framework.Reports
{
    public class ReportManager
    {
        public static IReportSetting CreateReportSetting()
        {
            return new ReportSetting();
        }

        public static IReportTable CreateReport(IReportSetting setting, DataTable table)
        {
            return new ReportTableController().CreateReportTable(setting, table);
        }

        public static string ConvertToHtml(IReportSetting setting, DataTable table)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(ToHtmlController.Instance.Convert(setting.GetPageHeader()));
            builder.AppendLine("<br>");
            builder.AppendLine(ToHtmlController.Instance.Convert(CreateReport(setting, table), setting.Width));
            builder.AppendLine("<br>");
            builder.AppendLine(ToHtmlController.Instance.Convert(setting.GetPageFooter()));
            return builder.ToString();
        }

        public static IReportSetting Deserialize(string content)
        {
            return XmlManager.Deserialize<ReportSetting>(content);
        }
    }
}
